b750c7
@@ -30,6 +30,7 @@
import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriParams;
 import org.apache.camel.spi.UriPath;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.jsse.SSLContextParameters;
 
 /**
@@ -240,7 +241,7 @@
public class MailConfiguration implements Cloneable {
             properties.put("javax.net.debug", "all");
         }
 
-        if (sslContextParameters != null && isSecureProtocol()) {
+        if (sslContextParameters != null && (isSecureProtocol() || isStartTlsEnabled())) {
             SSLContext sslContext;
             try {
                 sslContext = sslContextParameters.createSSLContext();
@@ -251,7 +252,7 @@
public class MailConfiguration implements Cloneable {
             properties.put("mail." + protocol + ".socketFactory.fallback", "false");
             properties.put("mail." + protocol + ".socketFactory.port", "" + port);
         }
-        if (dummyTrustManager && isSecureProtocol()) {
+        if (dummyTrustManager && (isSecureProtocol() || isStartTlsEnabled())) {
             // set the custom SSL properties
             properties.put("mail." + protocol + ".socketFactory.class", "org.apache.camel.component.mail.DummySSLSocketFactory");
             properties.put("mail." + protocol + ".socketFactory.fallback", "false");
@@ -269,6 +270,17 @@
public class MailConfiguration implements Cloneable {
                || this.protocol.equalsIgnoreCase("imaps");
     }
 
+    public boolean isStartTlsEnabled() {
+        if (additionalJavaMailProperties != null) {
+            return ObjectHelper.equal(
+                additionalJavaMailProperties.getProperty("mail." + protocol + ".starttls.enable"),
+                "true",
+                true);
+        }
+
+        return false;
+    }
+
     public String getMailStoreLogInformation() {
         String ssl = "";
         if (isSecureProtocol()) {
